// import { reactive } from 'vue';
import { apiService } from '../../api/apiService';
import { getMaintainexamDataList } from '../../api/server';
import { ssm } from '../../util/ServerLang';
import { selfI18n } from '../../i18n';

export default function useMaintaincheckDataSetup () {
    const $t = selfI18n;
    // 服务进度操作类型
    // 派单：sendorder，转派：redeploy，结单：complete，验收：accept
    const operatorform = [
        {
            value: 'sendorder',
            label: $t('wp-pai-dan')
        },
        {
            value: 'redeploy',
            label: $t('wp-zhuan-pai')
        },
        {
            value: 'complete',
            label: $t('wp-jie-dan')
        },
        {
            value: 'accept',
            label: $t('wp-yan-shou')
        }
    ];

    const operatetypeformat = (child) => {
        const resdata = operatorform.filter(item => item.value === child.operatetype);
        if (resdata.length === 0 || resdata === undefined) {
            return child.operatetype;
        } else {
            return resdata[0].label;
        }
    };

    const operatorcheckDescFormat = (child) => {
        const resdata = operatorform.filter(item => item.value === child.operatetype);
        if (resdata.length === 0 || resdata === undefined) {
            return child.operatetype;
        }
        switch (resdata[0].value) {
        case 'sendorder':
            return $t('wp-xi-tong-yi-pai-dan-gei') + child.receiver + ' (' + (child.receiveralias || child.receiver) + ') ';
        case 'redeploy':
            return child.operator + ' (' + (child.operatoralias || child.operator) + ') ' + $t('wp-zhuan-pai-gei') + child.receiver + ' (' + (child.receiveralias || child.receiver) + ') ';
        case 'complete':
            return child.operator + ' (' + (child.operatoralias || child.operator) + ') ' + $t('wp-yi-jie-shu-le-wei-jian-gong-dan');
        case 'accept':
            return child.operator + ' (' + (child.operatoralias || child.operator) + ') ' + $t('wp-yi-yan-shou-wei-jian-gong-dan');
        };
    };

    // 获取服务客户列表
    const queryMaintianexamList = (param) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: getMaintainexamDataList,
                param: {
                    ...param

                },
                success: (data) => {
                    // customerObj.customer_options = data.value;
                    resolve(data);
                },
                fail: (data) => {
                    ssm(data);
                    reject(data);
                }
            });
        });
    };

    return {
        queryMaintianexamList,
        operatetypeformat,
        operatorcheckDescFormat
    };
}
